//用栈求解n皇后问题
#include <stdio.h>  
#include <stdlib.h>  
#define MAXN 100  
  
int n;  
int queens[MAXN];  
  
int conflict(int row, int col) {  
    for (int i = 0; i < row; i++) {  
        if (queens[i] == col || abs(queens[i] - col) == abs(i - row)) {  
            return 1;  
        }  
    }  
    return 0;  
}  
  
void backtrack(int row) {  
    if (row == n) {  
        for (int i = 0; i < n; i++) {  
            printf("%d ", queens[i]);  
        }  
        printf("\n");  
        return;  
    }  
    for (int col = 0; col < n; col++) {  
        if (!conflict(row, col)) {  
            queens[row] = col;  
            backtrack(row + 1);  
        }  
    }  
}  
int main() {  
    printf("Enter the number of queens: ");  
    scanf("%d", &n);  
    backtrack(0);  
    return 0;  
}